package br.com.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import br.com.bean.ClienteBean;
import br.com.bean.FuncionarioBean;

public class FuncionarioDAO {
	public void inserir(Connection conn, FuncionarioBean value) throws Exception {
		String sql ="INSERT INTO funcionario(nome, salario, cargo, cnh, telefone, endereco, numero, cidade,bairro, dataadm, datadem, cpf)VALUES (?, ?, ?, ?, ?, ?, ?, ?,?, ?, ?, ?)";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, value.getNome());
		ps.setDouble(2, value.getSalario());
		ps.setString(3, value.getCargo());
		ps.setString(4, value.getCnh());
		ps.setString(5, value.getTelefone());
		ps.setString(6, value.getEndereco());
		ps.setString(7, value.getNumero());
		ps.setInt(8, value.getCidade().getId());
		ps.setDate(9, value.getDataAdm());
		ps.setDate(10, value.getDataDem());
		ps.setString(11, value.getCpf());
	}

	public ArrayList<FuncionarioBean> lista(Connection conn) throws SQLException {

			String sql = "SELECT id, nome FROM funcionario";
			
			PreparedStatement ps = conn.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			ArrayList<FuncionarioBean> funcionarioBean = new ArrayList<FuncionarioBean>();
			while(rs.next()){
				FuncionarioBean funcionario = new FuncionarioBean();
				funcionario.setId(rs.getInt("id"));
				funcionario.setNome(rs.getString("nome"));
				funcionarioBean.add(funcionario);
			}
			rs.close();
			ps.close();
			return funcionarioBean;
	}

	}


